﻿using System.Xml;

using octalforty.Syndication.Core;

namespace octalforty.Syndication.Core.Rss.Aggregators
{
    /// <summary>
    /// Base RSS aggregator.
    /// </summary>
    public sealed class RssAggregator : AggregatorBase
    {
        /// <summary>
        /// Initializes a new instance of <see cref="RssAggregator"/> class.
        /// </summary>
        public RssAggregator()
        {
        }

        #region AggregatorBase Members
        /// <summary>
        /// Internal method, invoked from the implementation of <see cref="AggregatorBase.Aggregate"/>.
        /// </summary>
        /// <param name="feedDocument"></param>
        /// <param name="syndicationFeed"></param>
        /// <remarks>
        /// The implementation must not invoke <see cref="IAggregator.Aggregate"/> 
        /// on the <see cref="AggregatorBase.NextAggregator"/>.
        /// </remarks>
        protected override void InternalAggregate(XmlDocument feedDocument, ref ISyndicationFeed syndicationFeed)
        {
            //
            // First, check whether feedDocument is an RSS feed.
            if(feedDocument.DocumentElement.Name != "rss")
                throw new SyndicationException();

            //
            // Create an instance of RssFeed for all aggregators to use.
            syndicationFeed = new RssFeed();
        }
        #endregion
    }
}
